# Maintainer: Patrick Stewart <patstew@gmail.com>
# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=jupyter_core
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.1.3
pkgrel=1
pkgdesc='A base package on which Jupyter projects rely (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/jupyter/jupyter_core'
license=('spdx:BSD-3-Clause')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-platformdirs
    ${MINGW_PACKAGE_PREFIX}-python-pywin32
    ${MINGW_PACKAGE_PREFIX}-python-traitlets)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-hatchling
    ${MINGW_PACKAGE_PREFIX}-python-installer)
checkdepends=(
    ${MINGW_PACKAGE_PREFIX}-python-pytest
    ${MINGW_PACKAGE_PREFIX}-python-nose)
options=('!strip')
source=(https://pypi.org/packages/source/${_realname::1}/${_realname/_/-}/${_realname}-${pkgver}.tar.gz)
sha256sums=('82e1cff0ef804c38677eff7070d5ff1d45037fef01a2d9ba9e6b7b8201831e9f')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  pytest -v \
    --deselect jupyter_core/tests/test_command.py::test_not_on_path \
    --deselect jupyter_core/tests/test_command.py::test_path_priority \
    --deselect jupyter_core/tests/test_command.py::test_argv0 \
    --deselect jupyter_core/tests/test_paths.py::test_jupyter_path_prefer_env # https://github.com/jupyter/jupyter_core/issues/208
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  find "${pkgdir}/" -type d -empty -delete

  install -Dm644 "COPYING.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
